<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateCmsBasesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('cms_bases')) {
            Schema::create('cms_bases', function (Blueprint $table) {
                $table->id();
                $table->integer('cid')->comment('CMS分类ID:cms_categories.id');
                $table->string('title')->comment('标题');
                $table->string('resume')->nullable()->comment('摘要');
                $table->longText('content')->nullable()->comment('内容');
                $table->integer('order')->default(0)->comment('排序,值越大权重越大');
                // ------以下字段都可以设置为扩展字段------
                $table->string('author')->nullable()->comment('作者');
                $table->string('source')->nullable()->comment('来源');
                $table->string('thumb_img')->nullable()->comment('缩略图');
                $table->integer('view')->default(0)->comment('浏览量');
                $table->integer('comment')->default(0)->comment('评论量');
                $table->integer('likes')->default(0)->comment('点赞量');
                $table->integer('collect')->default(0)->comment('收藏量');
                $table->integer('share')->default(0)->comment('分享量');
                $table->string('tags')->nullable()->comment('标签');
                $table->enum('is_top', ['yes', 'no'])->default('no')->comment('是否置顶');
                $table->enum('is_recommended', ['yes', 'no'])->default('no')->comment('是否推荐');
                $table->timestamp('publish_at')->nullable()->comment('发布时间');
                $table->enum('status', ['yes', 'no'])->default('no')->comment('状态:yes已发布,no未发布');
                $table->string('seo_keywords')->nullable()->comment('关键字');
                $table->string('seo_description')->nullable()->comment('描述');
                $table->softDeletes();
                $table->timestamps();
                $table->index(['title', 'cid']);
            });
            DB::statement("ALTER TABLE `cms_bases` comment 'CMS内容基础表'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cms_bases');
    }
}
